今天我整理一下之前自己在Linux 家用或工作主機上檢視統硬體的方法。
lscpu可以取得CPU的架構(x86, x86_64...等等)、核心數量、執行緒數量、頻率(從不同核心的運行頻率中挑選最大的來顯示)和快取大小。使用方法很簡單,直接在終端機輸入以下指令即可
lscpu
> $ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 39 bits physical, 48 bits virtual
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 78
Model name: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
Stepping: 3
CPU MHz: 2884.014
CPU max MHz: 3000.0000
CPU min MHz: 400.0000
BogoMIPS: 4992.00
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
Linux系統會將部分CPU的資訊即時地存在於記憶體中,對應的檔案路徑在「/proc/cpuinfo」,可以使用以下指令來查看這個檔案路徑所儲存的內容
cat /proc/cpuinfo
我這邊就不放了,因為他會把每一顆核心詳細資訊列出。
cat /proc/cpuinfo | grep MHz
$ cat /proc/cpuinfo | grep MHz
cpu MHz : 2100.008
cpu MHz : 2098.189
cpu MHz : 2100.010
cpu MHz : 2099.967
watch -n 1 "cat /proc/cpuinfo | grep MHz"
sudo apt install lm-sensors
yes | sudo sensors-detect
watch -n 1 "sensors"
iwlwifi_1-virtual-0
Adapter: Virtual device
temp1: +35.0°C
dell_smm-virtual-0
Adapter: Virtual device
fan1: 3504 RPM
acpitz-acpi-0
Adapter: ACPI interface
temp1: +25.0°C (crit = +107.0°C)
coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +48.0°C (high = +100.0°C, crit = +100.0°C)
Core 0: +47.0°C (high = +100.0°C, crit = +100.0°C)
Core 1: +46.0°C (high = +100.0°C, crit = +100.0°C)
pch_skylake-virtual-0
Adapter: Virtual device
temp1: +46.0°C
自從我工作的電腦 nvme SSD 硬碟無預警壞掉之後,我就在想有什麽工具可以知道SSD健康度,後來我找到這兩款:smartmontools
nvme-cli
smartmontools
可以檢測 SATA 介面, nvme 介面無法
sudo apt install smartmontools
$ sudo smartctl -i /dev/sdb | grep "SMART support is"
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
$ sudo smartctl -i /dev/nvme0n1
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.10.0-13-amd64] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Model Number: XPG GAMMIX S50 Lite
Serial Number: 2K462LQJ9JR7
Firmware Version: 82A7T9PA
PCI Vendor/Subsystem ID: 0x1cc1
IEEE OUI Identifier: 0x486834
Controller ID: 0
NVMe Version: 1.4
Number of Namespaces: 1
Namespace 1 Size/Capacity: 1,024,209,543,168 [1.02 TB]
Namespace 1 Utilization: 67,701,051,392 [67.7 GB]
Namespace 1 Formatted LBA Size: 512
Local Time is: Mon Apr 11 09:42:11 2022 CST
nvme-cli
只能支援 nvme 介面
sudo apt install nvme-cli
$ sudo nvme list
Node SN Model Namespace Usage Format FW Rev
---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1 202628D66F33 CT500P1SSD8 1 500.11 GB / 500.11 GB 512 B + 0 B P3CR021
sudo watch -n 1 nvme smart-log /dev/nvme0n1 # 動態檢視
$ sudo nvme smart-log /dev/nvme0n1
Smart Log for NVME device:nvme0n1 namespace-id:ffffffff
critical_warning : 0
temperature : 33 C
available_spare : 100%
available_spare_threshold : 5%
percentage_used : 1%
data_units_read : 4,457,364
data_units_written : 6,119,233
host_read_commands : 65,279,454
host_write_commands : 101,740,695
controller_busy_time : 2,024
power_cycles : 880
power_on_hours : 2,525
unsafe_shutdowns : 160
media_errors : 0
num_err_log_entries : 264
Warning Temperature Time : 0
Critical Composite Temperature Time : 0
Temperature Sensor 1 : 33 C
Thermal Management T1 Trans Count : 0
Thermal Management T2 Trans Count : 0
Thermal Management T1 Total Time : 0
Thermal Management T2 Total Time : 0
udevadm monitor
KERNEL[3434.892293] add /devices/pci0000:00/0000:00:14.0/usb1/1-1 (usb)
KERNEL[3434.893220] add /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0 (usb)
KERNEL[3434.893454] bind /devices/pci0000:00/0000:00:14.0/usb1/1-1 (usb)
UDEV [3434.935105] add /devices/pci0000:00/0000:00:14.0/usb1/1-1 (usb)
KERNEL[3435.021095] add /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/host2 (scsi)
KERNEL[3435.022326] add /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0/host2/scsi_host/host2 (scsi_host)
KERNEL[3435.022768] bind /devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0 (usb)
sudo lsscsi
[2:0:0:0] disk General UDisk 5.00 /dev/sda
[N:0:0:1] disk CT500P1SSD8__1 /dev/nvme0n1